
#include <BPickItem>

#include "member_BPickItem.h"
#include "member_BShape.h"

using namespace BWE;

#define member						(*(member_BPickItem*)_ptr)
#define member_allocate()			_ptr = new member_BPickItem(this)
#define member_release()			delete (member_BPickItem*)_ptr

BPickItem::BPickItem()
{
	member_allocate();
}
BPickItem::BPickItem(BReal ratio)
{
	member_allocate();
	member.ratio = ratio;
}
BPickItem::BPickItem(Primitive primitive)
{
	member_allocate();
	member.primitive = primitive;
}
BPickItem::BPickItem(const BString& name) : BObject(name)
{
	member_allocate();
}
BPickItem::BPickItem(const BPickItem& other) : BObject(other.name())
{
	member_allocate();
	member.group = item_member(&other)->group;
	member.node = item_member(&other)->node;
	member.shape = item_member(&other)->shape;
	member.element = item_member(&other)->element;
	member.primitive = item_member(&other)->primitive;
	member.ratio = item_member(&other)->ratio;
	member.point = item_member(&other)->point;
	member.normal = item_member(&other)->normal;
	member.index = item_member(&other)->index;
}
BPickItem::~BPickItem()
{

}

void BPickItem::setGroup(BGroup* group)
{
	member.group = group;
}
BGroup* BPickItem::group() const
{
	return member.group;
}

void BPickItem::setNode(BNode* node)
{
	member.node = node;
}
BNode* BPickItem::node() const
{
	return member.node;
}

void BPickItem::setShape(BShape* shape)
{
	member.shape = shape;
}
BShape* BPickItem::shape() const
{
	return member.shape;
}

void BPickItem::setElement(BElement* element)
{
	member.element = element;
}
BElement* BPickItem::element() const
{
	return member.element;
}

void BPickItem::setPrimitive(Primitive primitive)
{
	member.primitive = primitive;
}
Primitive BPickItem::primitive() const
{
	return member.primitive;
}

void BPickItem::setRatio(BReal ratio)
{
	member.ratio = ratio;
}
BReal BPickItem::ratio() const
{
	return member.ratio;
}

void BPickItem::setPoint(const BVector& point)
{
	member.point = point;
}
const BVector& BPickItem::point() const
{
	return member.point;
}

void BPickItem::setNormal(const BVector& normal)
{
	member.normal = normal;
}
const BVector& BPickItem::normal() const
{
	return member.normal;
}

void BPickItem::setIndex(int index)
{
	member.index = index;
}
int BPickItem::index() const
{
	return member.index;
}

bool BPickItem::empty() const
{
	return !member.node && !member.shape;
}

BMatrix BPickItem::matrix() const
{
	BMatrix matrix = member.shape->matrix();
	if (member.node)
		matrix *= member.node->matrix();
	return matrix;
}
BVector BPickItem::absolutePoint() const
{
	BVector point = member.point;
	if (member.shape)
		point *= member.shape->matrix();
	if (member.node)
		point *= member.node->matrix();
	return point;
}
BVector BPickItem::absoluteNormal() const
{
	BVector normal = member.normal;
	if (member.shape)
	{
		normal *= member.shape->rotate();
	}
	if (member.node)
	{
		normal *= member.node->rotate();
	}
	return normal;
}

